package com.hzw.saas.web.app.client.app.controller;

import com.hzw.saas.api.client.IClientAppService;
import com.hzw.saas.api.client.bo.ClientAppBo;
import com.hzw.saas.api.client.query.ClientAppQuery;
import com.hzw.saas.common.util.MapperUtil;
import com.hzw.saas.web.app.client.app.dto.ClientAppDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * @author hankun
 */
@RestController
@RequestMapping("client/app")
@Api(tags = "软件应用")
public class ClientAppController {

    @Resource
    private IClientAppService clientAppService;

    @GetMapping("version")
    @ApiOperation(value = "获取软件应用版本信息", notes = "获取软件应用版本信息")
    public ResponseEntity<ClientAppDto> getClientAppVersion(@Validated ClientAppQuery clientAppQuery) {
        ClientAppBo clientAppBo = clientAppService.getLatestVersion(clientAppQuery);
        ClientAppDto clientAppDto = MapperUtil.nf().map(clientAppBo, ClientAppDto.class);
        return ResponseEntity.ok(Objects.isNull(clientAppDto) ? MapperUtil.nf().map(clientAppQuery, ClientAppDto.class) : clientAppDto);
    }

}
